AudioClipPlayerPlays and manages AudioClip instances inside a Channel.
import { AudioClipPlayer, AudioClip, Channel } from "@fluex/fluexgl-dsp";
...
const context = audioDevice.getContext();
const channel = audioDevice.createChannel();
const player = new AudioClipPlayer(context);
const clip = new AudioClip(audioSourceData);
player.attachAudioClip(clip);
player.send(channel);
Constructs a new AudioClipPlayer and wires it into the provided Channel.
new AudioClipPlayer(context: AudioContext): AudioClipPlayer;
context: AudioContext - The AudioContext used to create this player’s internal audio nodes.label: stringA human-readable label for debugging / UI purposes. Defaults to "AudioClipPlayer".
id: stringA unique id, automatically generated on construction. Should NOT be changed.
audioClips: AudioClip[]All AudioClip instances currently attached to this player.
outputGainNode: GainNode | nullInternal output gain node. This is where volume is applied and what gets connected to a target via send().
context: AudioContext | nullThe AudioContext used to create this player’s internal nodes. Set during construction.
channel: Channel | Master | nullThe current send target (Channel or Master) this player is connected to. null when not routed.
attachAudioClip(audioClip: AudioClip): voidAttaches an AudioClip to this player. Initializes the clip with this player and stores it in audioClips. Logs an error if the clip is already attached.
audioClip: AudioClip - The clip to attach.voiddetachAudioClip(clip: AudioClip): voidDetaches a previously attached AudioClip from this player. Logs an error if the clip is not attached.
clip: AudioClip - The clip to detach.voidsend(channel: Channel | Master): voidRoutes this player’s outputGainNode to a Channel or the Master by connecting to the target’s input node.
voidunsend(): voidDisconnects this player’s outputGainNode from its current target (if any) and clears channel.
No arguments
voidsetVolume(value: number): voidSets the output volume by writing to outputGainNode.gain.value. The value is clamped between 0 and 1.
value: number - Volume from 0.0 (silent) to 1.0 (full scale). Values outside the range are clamped.voidstopAll(): voidStops playback for all attached clips by calling stop() on each clip in audioClips.
No arguments
voiddispose(): voidStops all clips, disconnects routing, disconnects the output node, and clears internal references (clips, nodes, context, channel). Use when you no longer need this player.
No arguments
voidsetLabel(label: string): voidUpdates the label of this player.
label: string - New label.voidThis class does not emit custom events.
get length(): numberReturns the number of AudioClip instances currently attached to this player (audioClips.length).
get volume(): numberReturns the current output volume, read from outputGainNode.gain.value. Returns 0 when no output gain node is available.
import { AudioClip, Channel } from "@fluex/fluexgl-dsp";
const context = new AudioContext();
const channel = new Channel(context);
// Use the Channel-owned player in real usage
const clip = new AudioClip(audioSourceData);
channel.attachAudioClip(clip);
// Stop everything routed through the channel’s player
channel.audioClipPlayer.stopAll();